package com.Feifan.B;

public class J {
    public static class BNode{
        BNode lchild,rchild;
        char data;
    }
    public static BNode pre_mid_creatTree(String pre,String mid,int len){
        if(len == 0){
            return null;
        }
        char root = pre.charAt(0);
        BNode T = new BNode();
        T.data = root;
        int index = 0;
        while(mid.charAt(index)!=root){
            index++;
        }
        T.lchild = pre_mid_creatTree(pre.substring(1),mid,index);
        T.rchild = pre_mid_creatTree(pre.substring(1+index),mid.substring(index+1),len-index-1);
        return T;
    }
    public static void postOrder(BNode t){
        if(t!=null){
            postOrder(t.lchild);
            postOrder(t.rchild);
            System.out.print(t.data+" ");
        }
    }
    public static void main(String[] args) {
        BNode T;
        String pre = "ABDECFG";
        String mid = "DBEAFGC";
        String last = "DEBGFCA";
        System.out.println("先序-中序创建二叉树后的后序遍历为：");
        T = pre_mid_creatTree(pre,mid,7);
        postOrder(T);
    }

}